package com.mj;

import com.mj.entity.Member;
import com.mj.entity.Student;
import com.mj.entity.Teacher;
import com.mj.mapper.MemberMapper;
import com.mj.mapper.StudentMapper;
import com.mj.mapper.TeacherMapper;
import com.mj.mybatis.MyHelper;
import org.apache.ibatis.session.SqlSession;
import org.junit.Test;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Demo {
    @Test
    public void pp(){
        System.out.println("ssas");
    }
    @Test
    public void psp(){
        MyHelper<TeacherMapper> mh = new MyHelper<TeacherMapper>(TeacherMapper.class);
        //System.out.println(mh);
        TeacherMapper tm = mh.getMapper();
        //System.out.println(tm);
        /*MyHelper mh = new MyHelper();
        SqlSession ss = mh.getSession();
        TeacherMapper tm = ss.getMapper(TeacherMapper.class);*/
        Teacher ta = tm.queryById(3);
        System.out.println(ta.getTname());
        System.out.println(ta.getTid());
        System.out.println(ta.getSclass().getSname());
        //System.out.println("ss");
    }
    @Test
    public void pps(){
        MyHelper<MemberMapper> mh = new MyHelper<MemberMapper>(MemberMapper.class);
        //System.out.println(mh);
        MemberMapper tm = mh.getMapper();
        //System.out.println(tm);
        /*MyHelper mh = new MyHelper();
        SqlSession ss = mh.getSession();
        TeacherMapper tm = ss.getMapper(TeacherMapper.class);*/
        //Member ta = tm.queryById(3);
        //System.out.println(tm.queryById(3));
        //System.out.println(tm.queryByInt(3));
        List<Member> li = tm.queryAll();
        for (Member me : li){
            System.out.println(me.getName());
        }
        //System.out.println(tm.queryAll().size());
        //System.out.println(ta.getName());
        //System.out.println(ta.getOrders());
        //System.out.println(ta.get.getSname());
        //System.out.println("ss");
    }
    @Test
    public void stun(){
        MyHelper<StudentMapper> mh = new MyHelper<StudentMapper>(StudentMapper.class);
        StudentMapper st = mh.getMapper();
        Map<String,Object> map = new HashMap<String, Object>();
        //map为空时就查询所有信息
        //List<Student> li = st.search(map);
        map.put("name","唐%");
        map.put("dept","猛龙过江");
        List<Student> li = st.search(map);
        System.out.println(li);
    }
    @Test
    public void tri(){
        MyHelper<StudentMapper> mh = new MyHelper<StudentMapper>(StudentMapper.class);
        StudentMapper sm = mh.getMapper();
        Map<String,Object> m = new HashMap<String, Object>();
        m.put("id",36);
        m.put("age",999);
        m.put("name","乔峰");
        //m.put("dept","唐伯虎点秋香");
        m.put("score",2);
        sm.update(m);
        mh.close();
        //System.out.println(l);
    }
    @Test
    public void del(){
        MyHelper<StudentMapper> mh = new MyHelper<StudentMapper>(StudentMapper.class);
        StudentMapper sm = mh.getMapper();
        Map<String,Object> m = new HashMap<String, Object>();
        //m.put("id",59);
        //m.put("ids",new int[]{60,61});
        m.put("name","小鸟");
        sm.delete(m);
        mh.close();
    }
}
